package com.base.utils.helper;

import java.io.File;

import android.content.Context;
import android.os.Environment;

import com.base.common.cfg.BaseProperties;
import com.base.common.file.FileCommon;

public class CommonHelper {
	public static class Path {
		public static String getSdCard() {
			File sdcardDir = Environment.getExternalStorageDirectory();
			String rootPath = sdcardDir.getParent() + File.separator
					+ sdcardDir.getName() + File.separator;
			return rootPath;
		}

		public static String getBaseFull() {
			String rootPath = getSdCard()
					+ BaseProperties.getProperty("store_location", "base")
					+ File.separator;
			FileCommon.mkdirWithFullName(rootPath);
			return rootPath;
		}

		public static String getBaseUpdateFull() {
			String rootPath = getBaseFull()
					+ BaseProperties.getProperty("update_file_folder", "base")
					+ File.separator;
			FileCommon.mkdirWithFullName(rootPath);
			return rootPath;
		}

		public static String getConfigFull() {
			String rootPath = getBaseFull()
					+ BaseProperties.getProperty("conf_folder", "config")
					+ File.separator;
			FileCommon.mkdirWithFullName(rootPath);
			return rootPath;
		}

		public static String getBaseImagesFull() {
			String rootPath = getBaseFull()
					+ BaseProperties.getProperty("images_store_location",
							"images") + File.separator;
			FileCommon.mkdirWithFullName(rootPath);
			return rootPath;
		}

		public static String getBaseLogFull() {
			String rootPath = getBaseFull()
					+ BaseProperties.getProperty("log_file_folder", "logs")
					+ File.separator;
			FileCommon.mkdirWithFullName(rootPath);
			return rootPath;
		}

		public static String getBaseWebCacheFull() {
			String rootPath = getBaseFull()
					+ BaseProperties.getProperty("web_cache_location",
							"webcache") + File.separator;
			FileCommon.mkdirWithFullName(rootPath);
			return rootPath;
		}
	}

	public static class Resource {
		public static String getString(Context c, int rid) {
			return c.getResources().getString(rid);
		}

		public static Integer getInteger(Context c, int rid) {
			String str = c.getResources().getString(rid);
			Integer ret = null;
			try {
				ret = Integer.valueOf(Integer.parseInt(str));
			} catch (NumberFormatException e) {
				e.printStackTrace();
			}
			return ret;
		}

		public static String getArrayString(Context c, int rid, int index) {
			return c.getResources().getStringArray(rid)[index];
		}
	}
}
